Conversation
Reviewer's GuideThis PR integrates a Vitest-based testing framework with configuration and mocks, adds end-to-end unit tests for core DOM node grabbing utilities, and adjusts configuration imports to support stable test isolation. Class diagram for updated config import and test setupclassDiagram
class Config {
+defaultValues
+constructor()
}
class config {
+Config instance
}
class storage {
<<imported>>
}
config --> Config
config ..> storage : uses
class dom_test {
<<test file>>
+unit tests for grabNode
+unit tests for grabAllNode
}
dom_test ..> config : imports
dom_test ..> storage : uses (via config)
class setup {
<<test setup>>
+mocks for storage
+mocks for browser APIs
}
dom_test ..> setup : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `entrypoints/main/dom.ts:177` </location>
<code_context>
}
+// 检查节点是否可编辑(兼容 JSDOM 环境)
+function isContentEditableNode(node: any): boolean {
+ return node.isContentEditable ||
+ node.contentEditable === 'true' ||
</code_context>
<issue_to_address>
Consider normalizing contentEditable attribute checks.
Normalize the contentEditable value to lower case before comparison to ensure case-insensitive checks.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
function isContentEditableNode(node: any): boolean {
return node.isContentEditable ||
node.contentEditable === 'true' ||
node.getAttribute?.('contenteditable') === 'true';
}
=======
function isContentEditableNode(node: any): boolean {
return node.isContentEditable ||
(typeof node.contentEditable === 'string' && node.contentEditable.toLowerCase() === 'true') ||
(typeof node.getAttribute === 'function' && typeof node.getAttribute('contenteditable') === 'string' && node.getAttribute('contenteditable').toLowerCase() === 'true');
}
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
entrypoints/main/dom.ts
Outdated
| function isContentEditableNode(node: any): boolean { | ||
| return node.isContentEditable || | ||
| node.contentEditable === 'true' || | ||
| node.getAttribute?.('contenteditable') === 'true'; | ||
| } |
There was a problem hiding this comment.
suggestion: Consider normalizing contentEditable attribute checks.
Normalize the contentEditable value to lower case before comparison to ensure case-insensitive checks.
| function isContentEditableNode(node: any): boolean { | |
| return node.isContentEditable || | |
| node.contentEditable === 'true' || | |
| node.getAttribute?.('contenteditable') === 'true'; | |
| } | |
| function isContentEditableNode(node: any): boolean { | |
| return node.isContentEditable || | |
| (typeof node.contentEditable === 'string' && node.contentEditable.toLowerCase() === 'true') || | |
| (typeof node.getAttribute === 'function' && typeof node.getAttribute('contenteditable') === 'string' && node.getAttribute('contenteditable').toLowerCase() === 'true'); | |
| } |
| if (typeof Element !== 'undefined' && Element.prototype && typeof Element.prototype.getAttributeNames === 'undefined') { | ||
| console.log('Polyfilling Element.prototype.getAttributeNames'); | ||
| Element.prototype.getAttributeNames = function getAttributeNames() { | ||
| const attributes = this.attributes; |
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const attributes = this.attributes; | |
| const {attributes} = this; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
|
感谢pull request!这里可以提供1个范例吗 |
有的, 之前 这两个页面一些段落中带有超链接的话, 会被直接忽略掉 |
|
@sourcery-ai review |
| if (typeof Element !== 'undefined' && Element.prototype && typeof Element.prototype.getAttributeNames === 'undefined') { | ||
| console.log('Polyfilling Element.prototype.getAttributeNames'); | ||
| Element.prototype.getAttributeNames = function getAttributeNames() { | ||
| const attributes = this.attributes; |
There was a problem hiding this comment.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)
| const attributes = this.attributes; | |
| const {attributes} = this; |
Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide
|
@sourcery-ai summary |
问题在 #132 中修复, 我这里只保留了一些单元测试, 用以测试 grabNode, grabAllNode 等关键方法的行为
TODO: 更好的处理段落, 需要翻译的内容, 并将翻译好的内容添加回样式/超链接等行为
Summary by Sourcery
Set up Vitest-based testing environment, add unit tests for DOM node grabbing logic, and fix paragraph filtering in grabAllNode
Bug Fixes:
Enhancements:
Build:
Tests:
Chores: